package com.nannybear.Model;

import java.util.ArrayList;
import java.util.Observer;

/**
 * @brief Class which contain the temperature threshold information and notify observers
 */
public class TemperatureThreshold extends Constant{
    /********** DECLARATIONS **********/
    private ArrayList<Observer> observers;
    private int valueTempThreshold;


/************ METHODS ************/
    /**
     * @brief Constructor.
     */
    public TemperatureThreshold(){
        this.observers = new ArrayList<>();
        valueTempThreshold = 0;
    }

    /**
     * @brief Change the temperature threshold by notify observer.
     */
    public void changeThreshold(int tempThreshold){
        this.valueTempThreshold = tempThreshold;
        notifyObservers();
    }

    /**
     * @brief add the class as observable
     */
    public void addObserver(Observer obs){
        observers.add(obs);
    }

    /**
     * @brief delete the class as observable
     */
    public synchronized void deleteObserver(Observer obs){
        observers.remove(obs);
    }

    /**
     * @brief notify the observers
     */
    public void notifyObservers(){
        for (int i = 0; i < observers.size(); i++) {
            observers.get(i).update(this, this.valueTempThreshold);
        }
    }
}
